<%--
  Created by IntelliJ IDEA.
  User: hp
  Date: 2021-03-25
  Time: 8:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="<%=request.getContextPath()%>/"/>
    <link rel="stylesheet" href="webjars/layui/2.5.5/css/layui.css">
</head>
<body>
<div class="layui-container">
    <form class="layui-form layui-inline">
        <div class="layui-input-inline">
            药品查询:
        </div>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="drugname" placeholder="根据药品名称进行查询">
        </div>
        <div class="layui-input-inline">
            <button type="button" class="layui-btn" id="chaxun" onclick="search()">查询</button>
        </div>
    </form>



    <table  id="storeTb" lay-filter="storeTb"></table>

</div>
<%--修改和删除 id=active--%>
<script type="text/html" id="active">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left: 0px">
                <%--                    <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">--%>
<%--                <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="update">修改</button>--%>
                <button type="button" class="layui-btn layui-btn-danger layui-btn-sm" style="" lay-event="del" >删除</button>
            </div>
        </div>
    </form>
</script>
<script src="webjars/layui/2.5.5/layui.js"></script>
<script type="text/javascript">
    layui.use(["jquery","element","table","layer","form"],function () {
        let $ = layui.jquery;
        let table = layui.table;
        let layer = layui.layer;
        table.render({
            id: 'storeTb'
            , elem: '#storeTb'
            , url: '/store/searchAll' //数据接口
            // , toolbar: "#toolbar"
            , cols: [[ //表头\
                {field: 'id', type: 'checkbox'}
                , {field: 'drugname', title: '药名',}
                , {field: 'changshang', title: '厂商',}
                , {field: 'beginprice', title: '进价',}
                , {field: 'price', title: '销售价格',}
                , {field: 'begindate', title: '生产日期', hide: true,}
                , {field: 'date', title: '有效日期',}
                , {field: 'pihao', title: '批号',}
                , {field: 'beizhu', title: '备注', hide: true,}
                , {field: 'location', title: '药品位置', hide: true,}
                , {field: 'count', title: '库存',}
                , {field: 'unit', title: '单位',}
                , {field: 'guige', title: '规格',}
                , {field: 'zhi', title: '效期提示', width: 100,}
                , {title: '操作', templet: "#active", align: "center", width: 70}
            ]],
            page: {limit: 8, limits: [8, 16, 24, 32]}
        });
        table.on("tool(storeTb)", function ({event, data}) {
            switch (event) {
                case "del":
                    // alert("删除")
                    del(data.id);
                    break;
            }
        })
    })

    // //倒计时
    // function time(a) {
    //     layui.use(['util','jquery'], function(){
    //         var util = layui.util;
    //         let $=layui.jquery;
    //         var endTime = a
    //             ,serverTime = new Date().getTime();
    //
    //         console.log(a)
    //          return  util.countdown(endTime, serverTime, function(date,serverTime,timer){
    //             var str = "离过期还有"+date[0]+"天";
    //              $("#asd").html(str);
    //             // layui.$('#test').html('还有:'+ str);
    //             console.log(str)
    //
    //             return str;
    //         });
    //         console.log("出来了啊")
    //         return "wwd"
    // });
    // }

    //删除功能
    function del(c) {
        // console.log("我进到删除里了")
        // console.log(c)
        layui.use(["jquery","layer","table"],function () {
            let $=layui.jquery;
            let table=layui.table;
            let layer=layui.layer;
            layer.confirm('确认删除么？', {
                time: 20000, //20s后自动关闭
                btn: ['确定', '取消'],
                yes(){
                    $.post("/store/deleteStore",{id:c}).done(({msg}) => {
                        // console.log(msg);
                        layer.msg(msg);
                        table.reload("storeTb")

                    });
                }
            });



        })
    }

    function search() {
        layui.use(["jquery","table","layer"],function () {
            let $=layui.jquery;
            let layer=layui.layer;
            let table=layui.table;
            let drugname=$("#drugname").val();
            let where={drugname,page: 1};
            table.reload("storeTb",{where})
        })
    }
</script>
</body>
</html>
